package com.uenpay.im.ui.old.activity.transfer;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ScrollView;
import android.widget.TextView;

import com.qiyunxin.android.http.HttpInvokeResultCode;
import com.qyx.android.message.type.PacketType;
import com.uenpay.im.IMApplication;
import com.uenpay.im.R;
import com.uenpay.im.ui.old.activity.contacts.UserDetailActivity;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.weight.RoundImageView;
import com.uenpay.im.weight.ZProgressHUD;
import com.uenpay.util.app.base.BaseActivity;

/**
 * @author SL
 * @version 1.0
 * @copyRight http://www.qiyunxin.com
 * @E-mail:
 * @date 创建时间：2016-5-6 下午6:17:20
 * @function 转账详情
 */
public class TransferDetailActivity extends BaseActivity {

    private TextView nick_name, create_date_tv, reason_tv, account_tv,
            transfer_amount;
    private ZProgressHUD zProgressHUD;
    private RoundImageView avatar_iv;
    private String custId;
    private ScrollView scroll_view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        isFullScreen = true;
        super.onCreate(savedInstanceState);
    }

    @Override
    public View bindView() {
        return null;
    }

    @Override
    public int bindLayout() {
        return R.layout.activity_transfer_detail_layout;
    }

    @Override
    public void initView(View view) {
        String turnoverid = getIntent().getStringExtra("turnoverid");
        initView();
        initListener();
        getTransferDetail(turnoverid);
    }

    protected void initView() {
        zProgressHUD = new ZProgressHUD(this);
        ((TextView) findViewById(R.id.title_textview))
                .setText(R.string.transfer_detail);
        transfer_amount = (TextView) findViewById(R.id.transfer_amount);
        nick_name = (TextView) findViewById(R.id.nick_name);
        create_date_tv = (TextView) findViewById(R.id.create_date_tv);
        reason_tv = (TextView) findViewById(R.id.reason_tv);
        account_tv = (TextView) findViewById(R.id.account_tv);
        avatar_iv = (RoundImageView) findViewById(R.id.avatar_iv);
        scroll_view = (ScrollView) findViewById(R.id.scroll_view);
    }

    protected void initListener() {
        findViewById(R.id.account_layout).setOnClickListener(
                new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        if (!TextUtils.isEmpty(custId)) {
                            Intent intent = new Intent(
                                    TransferDetailActivity.this,
                                    UserDetailActivity.class);
                            intent.putExtra("cust_id", custId);
                            startActivity(intent);
                        }
                    }
                });
    }

    private void getTransferDetail(String turnoverid) {
        zProgressHUD.show();
        TransferHandle.getTransferDetail(turnoverid, new TransferHandle.ITarsferListener() {

            @Override
            public void getTarsferResult(int status, String msg,
                                         TransferEntity mTransferEntity) {
                zProgressHUD.dismiss();
                if (status == HttpInvokeResultCode.RESULT_OK) {
                    if (mTransferEntity != null) {
                        custId = mTransferEntity.fcustid + "";
                        nick_name.setText(mTransferEntity.fnickname);
                        transfer_amount.setText(mTransferEntity.amount);
                        create_date_tv.setText(mTransferEntity.createtime);
                        if (!TextUtils.isEmpty(mTransferEntity.fmobile)) {
                            String fmobile = mTransferEntity.fmobile;
                            account_tv.setText(fmobile.substring(0, 3) + "****"
                                    + fmobile.substring(8, fmobile.length()));
                        }
                        avatar_iv.SetUrl(APIConfiguration.getAvatarUrlNormal(
                                mTransferEntity.fcustid + "",
                                PacketType.PERSONAL));
                        if (!TextUtils.isEmpty(mTransferEntity.memo)) {
                            reason_tv.setText(mTransferEntity.memo);
                        }
                        scroll_view.setVisibility(View.VISIBLE);
                    }
                } else if (!TextUtils.isEmpty(msg)) {
                    IMApplication.showToast(msg);
                }
            }
        });
    }
}
